﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_tblCatalog : System.Web.UI.Page
{
    Product pd = new Product();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack == false)
        {
            txtCatalogID.Text = pd.GetCatalogID();
            grvData.DataSource = pd.GetCatalog();
            grvData.DataBind();
        }
    }
    protected void btnSummit_Click(object sender, EventArgs e)
    {
        if(pd.AddCatalog(pd.GetCatalogID(),txtCatalogName.Text))
        {
            txtCatalogID.Text =pd.GetCatalogID();
            txtCatalogName = null;
        }
    }
    protected void btnSearch0_Click(object sender, EventArgs e)
    {
        if(""!=txtSearch.Text.Trim())
        {
            grvData.DataSource = pd.GetCatalogByName(txtSearch.Text);
            grvData.DataBind();
        }
        else
        {
            lblError1.Visible = true;
            lblError1.Text = "Enter Categories name !";
        }
    }
    protected void grvDataCancel(object sender, GridViewCancelEditEventArgs e)
    {
        grvData.EditIndex = -1;
        grvData.DataSource = pd.GetCatalog();
        grvData.DataBind();
    }
    protected void grvDataDelete(object sender, GridViewDeleteEventArgs e)
    {
        string id = grvData.DataKeys[e.RowIndex].Value.ToString();
        if (pd.DelCatalog(id))
        {
            grvData.DataSource = pd.GetCatalog();
            grvData.DataBind();
        }
    }
    protected void grvDataEdit(object sender, GridViewEditEventArgs e)
    {
        grvData.EditIndex = e.NewEditIndex;
        grvData.DataSource = pd.GetCatalog();
        grvData.DataBind();
    }
    protected void grvDataUpload(object sender, GridViewUpdateEventArgs e)
    {
        if (pd.UpdateCatalog(grvData.DataKeys[e.RowIndex].Value.ToString(), (grvData.Rows[e.RowIndex].Cells[1].Controls[0] as TextBox).Text))
        {
            grvData.DataSource = pd.GetCatalog();
            grvData.DataBind();
        }
    }
    protected void grvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvData.PageIndex = e.NewPageIndex;
        grvData.DataSource = pd.GetCatalog();
        grvData.DataBind();
    }
}